package com.shine.demo.leetCode.leetCode1029;

import com.shine.demo.leetCode.entity.TreeNode;

import java.util.LinkedList;
import java.util.List;

/**
 * 二叉树的中序遍历
 * <p>
 * 给定一个二叉树的根节点 root ，返回 它的 中序 遍历 。
 */
public class InorderTraversal {
    private static List<Integer> res = new LinkedList<>();

    public static void main(String[] args) {
        TreeNode t1 = new TreeNode(1);
        TreeNode t2 = new TreeNode(2);
        TreeNode t3 = new TreeNode(3);
        t1.right = t2;
        t2.left = t3;
        System.out.println(inorderTraversal(t1));
    }

    public static List<Integer> inorderTraversal(TreeNode root) {
        //递归写入数组
        if (root != null) {
            inorderTraversal(root.left);
            res.add(root.val);
            inorderTraversal(root.right);
        }
        return res;

    }

}
